/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ConsultaEntregasView.java
 *
 * Created on 30-ene-2011, 12:55:15
 */

package Vista.TareaRealizada;

import Modelo.Entidades.TareaRealizada;
import Modelo.Entidades.Usuario;
import Vista.SesionActual;

/*
 *  Proyecto eJAM [G12]
 *  Miembros:
 *      - Javier Ruiz Hidalgo
 *      - Adrian Ramos Cápitas
 *      - Miguel Alejandro Esteban Ordóñez
 */

public class ConsultaEntregasView extends javax.swing.JPanel {

    private TareaRealizadaViewImpl tareaRealizadaView;
    private TareaRealizadaTableModel tareaRealizadaTableModel;

    /** Creates new form ConsultaEntregasView */
    public ConsultaEntregasView(TareaRealizadaViewImpl tareaRealizadaView) {
        this.tareaRealizadaView = tareaRealizadaView;
        this.tareaRealizadaTableModel = TareaRealizadaTableModel.create();

        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelTareas = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTablaTareasCorregidas = new javax.swing.JTable();
        jSeparator1 = new javax.swing.JSeparator();
        jConsultar = new javax.swing.JButton();

        setPreferredSize(new java.awt.Dimension(700, 600));

        jPanelTareas.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Tarea Corregidas", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        jTablaTareasCorregidas.setModel(tareaRealizadaTableModel);
        jScrollPane1.setViewportView(jTablaTareasCorregidas);

        javax.swing.GroupLayout jPanelTareasLayout = new javax.swing.GroupLayout(jPanelTareas);
        jPanelTareas.setLayout(jPanelTareasLayout);
        jPanelTareasLayout.setHorizontalGroup(
            jPanelTareasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTareasLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 648, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanelTareasLayout.setVerticalGroup(
            jPanelTareasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTareasLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jConsultar.setText("Consultar");
        jConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jConsultarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 680, Short.MAX_VALUE)
                    .addComponent(jPanelTareas, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jConsultar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelTareas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jConsultar)
                .addContainerGap(198, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jConsultarActionPerformed
        TareaRealizadaTableModel trtm = (TareaRealizadaTableModel)this.jTablaTareasCorregidas.getModel();
        int row = this.jTablaTareasCorregidas.getSelectedRow();

        if(row != -1){
            TareaRealizada tareaRealizada = trtm.getRow(row);
            new ConsultaTareaRealizadaView(tareaRealizada);
        }
    }//GEN-LAST:event_jConsultarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jConsultar;
    private javax.swing.JPanel jPanelTareas;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTable jTablaTareasCorregidas;
    // End of variables declaration//GEN-END:variables

    public void refrescaVista(){
        Usuario user = SesionActual.instancia().obtieneSesion().getUsuario();

        if(user.getClass().toString().equals("class Modelo.Entidades.AlumnoImpl")){
            this.tareaRealizadaTableModel.setTareasRealizadas(this.tareaRealizadaView.getModel().listarPorDNI(user.getDNI()));
        }
        else{
            this.tareaRealizadaTableModel.setTareasRealizadas(this.tareaRealizadaView.getModel().listar());
        }
    }
}
